﻿<%@ Page Language="C#" MasterPageFile="~/SMSMasterPage.master" AutoEventWireup="true"
    CodeFile="outbox.aspx.cs" Inherits="outbox" Title="Outbox" ValidateRequest="false"
    EnableEventValidation="false" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

    <script type="text/javascript">
        var TotalChkBx;
        var Counter;

        window.onload = function() {
            //Get total no. of CheckBoxes in side the GridView.
            TotalChkBx = parseInt('<%= this.GridViewSentMessages.Rows.Count %>');
            //Get total no. of checked CheckBoxes in side the GridView.
            Counter = 0;
        }

        function HeaderClick(CheckBox) {
            //Get target base & child control.
            var TargetBaseControl = document.getElementById('<%= this.GridViewSentMessages.ClientID %>');
            var TargetChildControl = "ChkBoxSelect";

            //Get all the control of the type INPUT in the base control.
            var Inputs = TargetBaseControl.getElementsByTagName("input");

            //Checked/Unchecked all the checkBoxes in side the GridView.
            for (var n = 0; n < Inputs.length; ++n)
                if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl, 0) >= 0)
                Inputs[n].checked = CheckBox.checked;
            //Reset Counter
            Counter = CheckBox.checked ? TotalChkBx : 0;
        }

        function ChildClick(CheckBox, HCheckBox) {
            //get target base & child control.
            var HeaderCheckBox = document.getElementById(HCheckBox);

            //Modifiy Counter;
            if (CheckBox.checked && Counter < TotalChkBx)
                Counter++;
            else if (Counter > 0)
                Counter--;

            //Change state of the header CheckBox.
            if (Counter < TotalChkBx)
                HeaderCheckBox.checked = false;
            else if (Counter == TotalChkBx)
                HeaderCheckBox.checked = true;
        }
        function HeaderClick1(CheckBox) {
            //Get target base & child control.
            var TargetBaseControl = document.getElementById('<%= this.GridView1.ClientID %>');
            var TargetChildControl = "ChkBoxSelectSch";

            //Get all the control of the type INPUT in the base control.
            var Inputs = TargetBaseControl.getElementsByTagName("input");

            //Checked/Unchecked all the checkBoxes in side the GridView.
            for (var n = 0; n < Inputs.length; ++n)
                if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl, 0) >= 0)
                Inputs[n].checked = CheckBox.checked;
            //Reset Counter
            Counter = CheckBox.checked ? TotalChkBx : 0;
        }

        function ChildClick(CheckBox, HCheckBox) {
            //get target base & child control.
            var HeaderCheckBox = document.getElementById(HCheckBox);

            //Modifiy Counter;
            if (CheckBox.checked && Counter < TotalChkBx)
                Counter++;
            else if (Counter > 0)
                Counter--;

            //Change state of the header CheckBox.
            if (Counter < TotalChkBx)
                HeaderCheckBox.checked = false;
            else if (Counter == TotalChkBx)
                HeaderCheckBox.checked = true;
        }
    </script>

    <cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0">
        <cc1:TabPanel ID="tp1" runat="server" HeaderText="Scheduled Messages">
            <ContentTemplate>
                <table width="100%">
                    <tr>
                        <td>
                            <asp:Panel ID="Panel1" runat="server">
                                <table width="100%" style="font-size: 12px;">
                                    <tr>
                                        <td style="text-align: left">
                                        </td>
                                        <td style="text-align: right">
                                            <table cellpadding="3" cellspacing="3" style="font-size: 12px;">
                                                <tr>
                                                    <td>
                                                        <asp:Button ID="btnCancel" runat="server" Text="Cancel Selected" OnClick="btnCancel_Click" />
                                                    </td>
                                                    <td>
                                                        <asp:Button ID="btnOptOutSelected" runat="server" Text="Optout Selected" OnClick="btnOptOutSelected_Click" />
                                                    </td>
                                                    <td>
                                                        <asp:Button ID="btnDeleteScheduled" runat="server" Text="Delete Selected" OnClick="btnDeleteScheduled_Click" />
                                                    </td>
                                                    <td>
                                                        <asp:Label ID="lblRecords" runat="server" Text="Per Page Records:"></asp:Label>
                                                    </td>
                                                    <td>
                                                        <asp:DropDownList ID="ddlShowRecords" runat="server" OnSelectedIndexChanged="ddlShowRecords_SelectedIndexChanged"
                                                            AutoPostBack="True">
                                                            <asp:ListItem>Select</asp:ListItem>
                                                            <asp:ListItem>100</asp:ListItem>
                                                            <asp:ListItem>200</asp:ListItem>
                                                            <asp:ListItem>250</asp:ListItem>
                                                            <asp:ListItem>500</asp:ListItem>
                                                        </asp:DropDownList>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>
                                <tr>
                                    <td colspan="2" style="font-size: 12px;">
                                        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowPaging="True"
                                            Width="100%" OnPageIndexChanging="GridView1_PageIndexChanging" EmptyDataText="No Data Exists!"
                                            AllowSorting="True" OnSorting="GridView1_Sorting" BackColor="#CCCCCC" BorderColor="#999999"
                                            BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2" ForeColor="Black"
                                            Style="font-size: 12px;">
                                            <Columns>
                                                <asp:TemplateField>
                                                    <ItemTemplate>
                                                        <asp:CheckBox ID="ChkBoxSelectSch" runat="server" />
                                                    </ItemTemplate>
                                                    <HeaderTemplate>
                                                        <asp:CheckBox runat="server" ID="HdrLevelCheckBox" onclick="javascript:HeaderClick1(this);" />
                                                    </HeaderTemplate>
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="From">
                                                    <ItemTemplate>
                                                        <asp:Label ID="lblMsgFrom" runat="server" Text='<%# Bind("MsgFrom") %>'></asp:Label>
                                                    </ItemTemplate>
                                                    <EditItemTemplate>
                                                        <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("MsgFrom") %>'></asp:TextBox>
                                                    </EditItemTemplate>
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="Recepient">
                                                    <ItemTemplate>
                                                        <asp:Label ID="lblMsgTo" runat="server" Text='<%# Bind("MsgTo") %>'></asp:Label>
                                                    </ItemTemplate>
                                                    <EditItemTemplate>
                                                        <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("MsgTo") %>'></asp:TextBox>
                                                    </EditItemTemplate>
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="Message">
                                                    <ItemTemplate>
                                                        <asp:Label ID="LnkBtnMsgText" runat="server" Text='<%# Bind("MsgText") %>'></asp:Label>
                                                    </ItemTemplate>
                                                    <EditItemTemplate>
                                                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("MsgText") %>'></asp:TextBox>
                                                    </EditItemTemplate>
                                                </asp:TemplateField>
                                                <asp:TemplateField Visible="False">
                                                    <ItemTemplate>
                                                        <asp:Label ID="LblmsgIdSch" runat="server" Text='<%# Bind("msgid") %>'></asp:Label>
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:BoundField DataField="MsgStatus" HeaderText="Status" />
                                                <asp:TemplateField HeaderText="Replies" Visible="False">
                                                    <ItemTemplate>
                                                        <asp:Label ID="LblReplyCount" runat="server">0</asp:Label>
                                                    </ItemTemplate>
                                                    <EditItemTemplate>
                                                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                                                    </EditItemTemplate>
                                                </asp:TemplateField>
                                                <asp:BoundField DataField="SentDateTime" HeaderText="Server Time" SortExpression="SentDateTime" />
                                                <asp:BoundField DataField="ScheduleDateTime" HeaderText="Schedule Date" />
                                                <asp:TemplateField HeaderText="Delete">
                                                    <ItemTemplate>
                                                        <asp:ImageButton ID="ImgBtnDeleteSch" runat="server" ImageUrl="~/images/Delete-icon.png"
                                                            Style="height: 16px" Width="16px" />
                                                        <cc1:ConfirmButtonExtender ID="ImgBtnDeleteSch_ConfirmButtonExtender" runat="server"
                                                            ConfirmText="Do you really wish to delete this record?" Enabled="True" TargetControlID="ImgBtnDeleteSch">
                                                        </cc1:ConfirmButtonExtender>
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                            </Columns>
                                            <EditRowStyle BackColor="#2461BF" />
                                            <FooterStyle BackColor="#CCCCCC" />
                                            <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
                                            <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
                                            <RowStyle BackColor="White" />
                                            <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                                        </asp:GridView>
                                    </td>
                                </tr>
                            </asp:Panel>
                        </td>
                    </tr>
                </table>
            </ContentTemplate>
        </cc1:TabPanel>
        <cc1:TabPanel ID="tp2" runat="server" HeaderText="Sent & Canceled Messages">
            <ContentTemplate>
                <table width="100%">
                    <tr>
                        <td>
                            <asp:Panel ID="Panelsentmessages" runat="server">
                                <table width="100%" style="font-size: 12px;">
                                    <tr>
                                        <td style="text-align: left">
                                        </td>
                                        <td style="text-align: right">
                                            <table cellpadding="3" cellspacing="3">
                                                <tr>
                                                    <td>
                                                        <asp:Button ID="BtnDeleteAll" runat="server" Text="Delete Selected" OnClick="BtnDeleteAll_Click" />
                                                    </td>
                                                    <td>
                                                        Per Page Record:
                                                    </td>
                                                    <td>
                                                        <asp:DropDownList ID="ddlRecords" runat="server" AutoPostBack="True" 
                                                            onselectedindexchanged="ddlRecords_SelectedIndexChanged">
                                                            <asp:ListItem>Select</asp:ListItem>
                                                            <asp:ListItem>100</asp:ListItem>
                                                            <asp:ListItem>200</asp:ListItem>
                                                            <asp:ListItem>250</asp:ListItem>
                                                            <asp:ListItem>500</asp:ListItem>
                                                        </asp:DropDownList>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <asp:GridView ID="GridViewSentMessages" runat="server" AutoGenerateColumns="False"
                                                AllowPaging="True" Width="100%" OnPageIndexChanging="GridViewSentMessages_PageIndexChanging"
                                                EmptyDataText="No Data Exists!" AllowSorting="True" OnSorting="GridViewSentMessages_Sorting"
                                                BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px"
                                                CellPadding="4" CellSpacing="2" ForeColor="Black">
                                                <Columns>
                                                    <asp:TemplateField>
                                                        <ItemTemplate>
                                                            <asp:CheckBox ID="ChkBoxSelect" runat="server" />
                                                        </ItemTemplate>
                                                        <HeaderTemplate>
                                                            <asp:CheckBox runat="server" ID="HeaderLevelCheckBox" onclick="javascript:HeaderClick(this);"
                                                                OnCheckedChanged="HeaderLevelCheckBox_CheckedChanged" />
                                                        </HeaderTemplate>
                                                    </asp:TemplateField>
                                                    <asp:BoundField DataField="MsgFrom" HeaderText="From" />
                                                    <asp:BoundField DataField="MsgTo" HeaderText="Recepient" />
                                                    <asp:TemplateField HeaderText="Message">
                                                        <ItemTemplate>
                                                            <asp:Label ID="LnkBtnMsgText" runat="server" Text='<%# Bind("MsgText") %>'></asp:Label>
                                                        </ItemTemplate>
                                                        <EditItemTemplate>
                                                            <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("MsgText") %>'></asp:TextBox>
                                                        </EditItemTemplate>
                                                    </asp:TemplateField>
                                                    <asp:TemplateField Visible="False">
                                                        <ItemTemplate>
                                                            <asp:Label ID="LblmsgId" runat="server" Text='<%# Bind("msgid") %>'></asp:Label>
                                                        </ItemTemplate>
                                                    </asp:TemplateField>
                                                    <asp:BoundField DataField="MsgStatus" HeaderText="Status" />
                                                    <asp:TemplateField HeaderText="Replies" Visible="False">
                                                        <ItemTemplate>
                                                            <asp:Label ID="LblReplyCount" runat="server">0</asp:Label>
                                                        </ItemTemplate>
                                                        <EditItemTemplate>
                                                            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                                                        </EditItemTemplate>
                                                    </asp:TemplateField>
                                                    <asp:BoundField DataField="SentDateTime" HeaderText="Server Time" SortExpression="SentDateTime" />
                                                    <asp:BoundField DataField="ScheduleDateTime" HeaderText="Schedule Date" />
                                                    <asp:TemplateField HeaderText="Delete">
                                                        <ItemTemplate>
                                                            <asp:ImageButton ID="ImgBtnDelete" runat="server" ImageUrl="~/images/Delete-icon.png"
                                                                OnClick="ImgBtnDelete_Click" Style="height: 16px" Width="16px" />
                                                            <cc1:ConfirmButtonExtender ID="ImgBtnDelete_ConfirmButtonExtender" runat="server"
                                                                ConfirmText="Do you really wish to delete this record?" Enabled="True" TargetControlID="ImgBtnDelete">
                                                            </cc1:ConfirmButtonExtender>
                                                        </ItemTemplate>
                                                    </asp:TemplateField>
                                                </Columns>
                                                <EditRowStyle BackColor="#2461BF" />
                                                <FooterStyle BackColor="#CCCCCC" />
                                                <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
                                                <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
                                                <RowStyle BackColor="White" />
                                                <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                                            </asp:GridView>
                                        </td>
                                    </tr>
                                </table>
                            </asp:Panel>
                        </td>
                    </tr>
                </table>
            </ContentTemplate>
        </cc1:TabPanel>
    </cc1:TabContainer>
</asp:Content>
